package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_invoice_import_wizard;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_invoice_import_wizardSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_invoice_import_wizardService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[从文件中导入你的供应商账单。] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_invoice_import_wizardServiceImpl implements IAccount_invoice_import_wizardService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_invoice_import_wizardClientService account_invoice_import_wizardClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_invoice_import_wizardClientService.removeBatch(account_invoice_import_wizards) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_invoice_import_wizard clientModel = account_invoice_import_wizardClientService.createModel();
        clientModel.setId(id);
        account_invoice_import_wizardClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean update(Account_invoice_import_wizard account_invoice_import_wizard) {
        boolean bOk = false ;
        Iaccount_invoice_import_wizard clientModel = this.convert2Model(account_invoice_import_wizard,null);
        account_invoice_import_wizardClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_invoice_import_wizard) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Account_invoice_import_wizard> account_invoice_import_wizards, int batchSize) {

                        //account_invoice_import_wizardClientService.createBatch(account_invoice_import_wizards,batchSize) ;

    }

    @Override
    public void updateBatch(List<Account_invoice_import_wizard> account_invoice_import_wizards, int batchSize) {

        //account_invoice_import_wizardClientService.updateBatch(account_invoice_import_wizards,batchSize) ;

    }

    @Override
    public Account_invoice_import_wizard get(Integer id) {
        Iaccount_invoice_import_wizard clientModel = account_invoice_import_wizardClientService.createModel();
        clientModel.setId(id);
        account_invoice_import_wizardClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_invoice_import_wizard get(Account_invoice_import_wizard account_invoice_import_wizard) {
        Account_invoice_import_wizard retaccount_invoice_import_wizard = this.get(account_invoice_import_wizard.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_invoice_import_wizard.getClass(), account_invoice_import_wizard.getClass(), false);
        copier.copy(retaccount_invoice_import_wizard, account_invoice_import_wizard, null);
        return account_invoice_import_wizard ;
    }

    @Override
    public boolean create(Account_invoice_import_wizard account_invoice_import_wizard) {
        boolean bOk = false ;
        Iaccount_invoice_import_wizard clientModel = this.convert2Model(account_invoice_import_wizard,null);
        account_invoice_import_wizardClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_invoice_import_wizard);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_invoice_import_wizard> searchDefault(Account_invoice_import_wizardSearchContext context) {
        List<Account_invoice_import_wizard> list = new ArrayList<Account_invoice_import_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard> clientModelList = account_invoice_import_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_import_wizard>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据日记账查询
     */
    @Override
    public Page<Account_invoice_import_wizard> selectByOdoo_journal(Integer id){
        Account_invoice_import_wizardSearchContext context = new Account_invoice_import_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_import_wizard> list = new ArrayList<Account_invoice_import_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard> clientModelList = account_invoice_import_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_import_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_invoice_import_wizard> selectByOdoo_create(Integer id){
        Account_invoice_import_wizardSearchContext context = new Account_invoice_import_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_import_wizard> list = new ArrayList<Account_invoice_import_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard> clientModelList = account_invoice_import_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_import_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_invoice_import_wizard> selectByOdoo_write(Integer id){
        Account_invoice_import_wizardSearchContext context = new Account_invoice_import_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_import_wizard> list = new ArrayList<Account_invoice_import_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard> clientModelList = account_invoice_import_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_import_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_import_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_invoice_import_wizard convert2Model(Account_invoice_import_wizard domain , Iaccount_invoice_import_wizard model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_invoice_import_wizardClientService.createModel() ;
        }

         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getAttachment_idsDirtyFlag())
            model.setAttachment_ids(domain.getAttachment_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getJournal_id_textDirtyFlag())
            model.setJournal_id_text(domain.getJournal_id_text());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Account_invoice_import_wizard convert2Domain( Iaccount_invoice_import_wizard model ,Account_invoice_import_wizard domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_invoice_import_wizard();
        }

        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getAttachment_idsDirtyFlag())
            domain.setAttachment_ids(model.getAttachment_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getJournal_id_textDirtyFlag())
            domain.setJournal_id_text(model.getJournal_id_text());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
